﻿/************************************************************************

 This file is part of "10 Second Tim".

 "10 Second Tim" is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 "10 Second Tim" is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with "10 Second Tim".  If not, see <http://www.gnu.org/licenses/>.

************************************************************************/

// All code (c)2013 Scott Bevin. all rights reserved

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace LDE
{
	public class Sprite
	{
		public Vector2 Pos = Vector2.Zero;
		public Texture2D m_tex;
		public Vector2 origin;
		public SpriteEffects Effect = SpriteEffects.None;

		private List<Rectangle> m_frames = new List<Rectangle>( );

		public int Frame = 0;

		public Sprite( Texture2D tex, int frames )
		{
			Debug.Assert( tex != null, "Invalid Tex" );

			float frameWidth = (float)tex.Width / frames;

			for ( int i = 0; i < frames; ++i )
			{
				Rectangle r = new Rectangle( (int)i * (int)frameWidth, 0, (int)frameWidth, tex.Height );
				m_frames.Add( r );
			}

			m_tex = tex;
			origin = new Vector2(
				(float)frameWidth * 0.5f,
				(float)tex.Height * 0.5f );
		}

		public void Update( float dt )
		{
		}

		public void Render( SpriteBatch batch, Vector2 pos )
		{
			Render( batch, pos, 0.0f );
		}

		public void Render( SpriteBatch batch, Vector2 pos, float rotation )
		{
			batch.Draw( m_tex, pos, m_frames[ Frame ], Color.White, rotation, origin, 1.0f, Effect, 0.0f );
		}
	}
}